package com.kolon.business.main.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.kolon.business.app.dao.AppDao;
import com.kolon.framework.constant.Constant;
import com.kolon.framework.interfaces.SimpleController;

@Controller("com.kolon.business.main.controller.AppSetupCheckController")
public class AppSetupCheckController implements SimpleController {

	@Resource(name="AppDaoImpl")
	private AppDao appDao;
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@RequestMapping(value="/business/main/appSetupCheck.do")
	public ModelAndView controller(HttpServletRequest request,
		HttpServletResponse response) throws Exception {
		
		// 파라미터
		String appNm = request.getParameter("appNm");
		int cnt = 0;
		// 세션 아이디 및 암호 값을 불러옴
		HttpSession httpSession = request.getSession();
		Map userMap = (Map)httpSession.getAttribute(Constant.SESSION_USER_INFO);
		Map model = new HashMap();
		// 조회
		if ("ikenuc".equals(appNm)) 
			cnt = appDao.getTempUcUserMap(userMap);
		else
			cnt = appDao.getTempSignUserMap(userMap);
		// 등록
		if (cnt == 0) {
			if ("ikenuc".equals(appNm)) 
				appDao.insertTempUcUser(userMap);
			else
				appDao.insertTempSignUser(userMap);
		}
		// 리턴
		model.put("cnt", cnt);
		return new ModelAndView("jsonView", model);

	}

}